#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
#define endl '\n'
typedef long long LL;
const LL MOD = 998244353;
const int N = 5010;
LL f[N], g[N];

LL qpow(LL a, LL b, LL MOD)
{
	LL ret = 1;
	while(b)
	{
		if(b & 1) ret = ret * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return ret;
}

void init()
{
	int n = 5000;
	f[0] = 1;
	for(int i = 1; i <= n; i++) f[i] = f[i - 1] * i % MOD;
	g[n] = qpow(f[n], MOD - 2, MOD);
	for(int i = n - 1; i >= 0; i--) 
	{
		g[i] = g[i + 1] * (i + 1) % MOD;
	}
}
LL C(int n, int m)
{
	if(n < m) return 0;
	return f[n] * g[m] % MOD * g[n - m] % MOD;
}
void solve() 
{
    int tol; cin >> tol;
	unordered_map<LL, LL> mp;
	for(int i = 1; i <= tol; i++)
	{
		int x; cin >> x;
		mp[x]++;
	}
	int n = mp.size();
	vector<LL> a;
    for(auto t : mp)
    {
        a.push_back(t.second);
    }
	LL ans = 0;
	// 全都当成n / 2上取整
	for(int len = 1; len <= tol; len++)
	{
		ans += (len + 1) / 2 * C(tol, len) % MOD;
		ans %= MOD;
	}
	// 考虑绝对众数
	for(int i = 0; i < n; i++)
	{
		// t为当前颜色的绝对众数
		for(int t = 1; t <= a[i]; t++)
		{
			for(int left = 0; left < t; left++)
			{
				LL ret = t + left; // 当前子序列的总数
				LL del = (ret + 1) / 2 * C(a[i], t) % MOD * C(tol - a[i], left) % MOD;
				LL add = t *  C(a[i], t) % MOD * C(tol - a[i], left) % MOD;
				ans += add - del;
				ans = ((ans % MOD) + MOD) % MOD;
			}
		}
	}
	cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T = 1;
	cin >> T;
	init();
//  for(int i = 5000; i <= 5000; i++) cout << g[i] << " ";
	while(T--)
	{
        solve();
	}
	return 0;
}